package com.m3958.firstgwt.server.accesschecker;

import com.m3958.firstgwt.server.dao.WorkFlowProjectDao;
import com.m3958.firstgwt.server.model.WFChangeLog;
import com.m3958.firstgwt.server.model.WorkFlowProject;
import com.m3958.firstgwt.shared.type.SmartConstants;


public class WFChangeLogChecker extends BaseChecker<WFChangeLog> {

	@Override
	protected boolean canAdd() {
		boolean shared = reqPs.getBooleanValue("shared");
		String mid = reqPs.getStringValue("mid");
		if(shared){
			if(mid == null || "nop".equals(mid) || mid.length() != 36){
				return false;
			}
			WorkFlowProjectDao wfdao = injector.getInstance(WorkFlowProjectDao.class);
			WorkFlowProject wf = wfdao.findByUUID(mid);
			if(wf == null){
				return false;
			}
			if("public-editable".equals(wf.getShareType())){
				return true;
			}else if("public".equals(wf.getShareType())){
				if(reqPs.getStringValue("changeDelta","").length()<3){
					return true;
				}
			}else{
				return false;
			}
		}else{
			int uid = reqPs.getIdValue("uid");
			if(uid == SmartConstants.NONE_EXIST_MODEL_ID){
				return false;
			}
			if(su != null && uid == su.getUserId()){
				return true;
			}
		}
		
		return false;
	}

	@Override
	protected boolean canCustom() {
		return false;
	}

	@Override
	protected boolean canFetch() {
		return true;
	}

	@Override
	protected boolean canMyRpc() {
		return false;
	}

	@Override
	protected boolean canRemove() {
		return false;
	}

	@Override
	protected boolean canUpdate() {
		return false;
	}

}
